﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using PLAYXPERT.Interfaces;
using System.Windows.Forms;

namespace BackLib
{
    public class Settings
    {
        public KeySettings keySettings;

        PLAYXPERT.Interfaces.ISettingsStore settingsStore;

        public Settings(PLAYXPERT.Interfaces.ICore iCore)
        {
            settingsStore = iCore.GetSettingsStore();
            keySettings = new KeySettings();
            LoadSettings();
        }

        public class KeySettings
        {
            [PXPSetting(SettingName = "S4PG.KeyPTT")]
            public string KeyPTT;
            [PXPSetting(SettingName = "S4PG.KeyMTT")]
            public string KeyMTT;
            [PXPSetting(SettingName = "S4PG.KeyPTC")]
            public string KeyPTC;
            [PXPSetting(SettingName = "S4PG.HandlePTTKey")]
            public bool HandlePTTKey;
            [PXPSetting(SettingName = "S4PG.HandleMTTKey")]
            public bool HandleMTTKey;
            [PXPSetting(SettingName = "S4PG.HandlePTCKey")]
            public bool HandlePTCKey;
        }

        public void LoadSettings()
        {
            settingsStore.ReadSettingsIntoObject(keySettings);

            if (keySettings.KeyPTT == "")
            {
                CreateSettings();
            }
        }

        void CreateSettings()
        {
            keySettings.KeyPTT = "F1";
            keySettings.KeyMTT = "F2";
            keySettings.KeyPTC = "F3";
            keySettings.HandlePTTKey = true;
            keySettings.HandleMTTKey = true;
            keySettings.HandlePTCKey = true;
            SaveSettings();
        }

        public void SaveSettings()
        {
            settingsStore.WriteSettingsFromObject(keySettings);
        }
    }
}
